<template>
  <div class="admin-users-page">
    <GhNavBar title="用户-管理" />
    <div class="head">
        <van-search class="search"  v-model="value" placeholder="搜索标题"   />
        <van-button class="add-btn"  native-type="submit"  block  >
               添加用户
         </van-button>
    </div>
    <div class="user-list">
        <van-list v-if="items.length > 0">
            <div class="total_users">共有{{items.length}}条符合条件记录</div>
            <van-cell v-for="item1 in items" :key="item1.id" class="item1-item">
                <div class="itembox">
                    <div class="img-box">
                        <img :src="item1.avatar" alt="" >
                       </div>
                       <div class="centerInfo">
                        <div class="top">
                            <div class="name">{{ item1.username }}</div>
                            <div class="gender">性别：{{item1.gender}}</div>
                        </div>
                       <div class="bottom">
                            <div class="account">手机号码：{{item1.account}}</div>
                            <div class="email">电子邮箱：{{item1.email}}</div>
                       </div>
                      
                       </div>
                    
                    <div class="operate">
                     <van-button >编辑</van-button>
                     <van-button >禁用</van-button>
                    </div>
                </div>
              
            </van-cell>
          </van-list>
          <van-empty v-else description="暂无用户信息" />
    </div>


  </div>
</template>

<script setup>
import {ref,reactive,onMounted} from "vue"
import {getAllUsers} from '@/services/admin'
import {useRouter} from 'vue-router'
import {useUserStore}from '@/stores'
import { Toast, Dialog } from 'vant';
import 'vant/es/toast/style'
//搜素框输入的值响应式变量
const value=ref()
//获取全部用户信息
const fetchData=async()=>{
    const res=await getAllUsers()
    const rows=res.data
    rows.forEach(row => {
    const { totalChunks, base64Chunks } = row.avatar;
    let imageData;
    for (let i = 0; i < base64Chunks.length; i++) {
      const base64Data = base64Chunks.join('');
      imageData = `data:image/jpeg;base64,${base64Data}`;
      row.avatar = imageData;
    }
  });
  console.log(rows)
    items.value=rows
}

onMounted(fetchData)


const items=ref([])
</script>

<style lang="scss" scoped>
.admin-users-page{
    width: 100%;
    .head{
        display: flex;
        position: fixed;
        z-index: 999;
        justify-content: space-between;
        align-items: center;
        min-height: 30px;
        background-color: #fff;
         top:35px;
         padding: 0 10px;
         .search{
            flex: 1;
         }
         .add-btn{
            background-color: var(--gh-admin);
            color: #fff;
            font-size: 14px;
            font-family: '黑体';
            border-radius: 5px;
            height: 30px;
            width: 130px;
         }
     }
     .user-list{
        margin-top: 85px;
        padding:0 5px;
           .total_users{
                text-align: center;
                padding: 5px 0;
                font-size: 10px;
                color: var(--gh-text3);
            }
           .van-cell{
            background-color: #fff;
             border:1px solid var(--gh-line) ;
             margin-top: 8px;
           .itembox{
            display: flex;
            .img-box{
                width: 60px;
                height: 60px;
                border-radius: 10px;
	           border-bottom-left-radius: 20px;
	            border-top-right-radius: 20px;
	            border: 2px solid var(--projectColorLight);
                 img{
                    display: block;
                    width: 100%;
                    height: 100%;
                    border-radius: 10px;
	                border-bottom-left-radius: 20px;
	                border-top-right-radius: 20px;
	                border: 2px solid var(--projectColorLight);
                }
            }
            .centerInfo{
                margin-left: 10px;
                flex: 1;
                .top{
                    position: relative;
                    font-size: 16px;
                    font-family: '楷体';
                    display: flex;
                    align-items: center;
                    .gender{
                        font-size: 12px;
                        position: absolute;
                        right: 15px;
                        color: var(--gh-primary);
                    }
                   
                }
                .bottom{
                    margin-top: 5px;
                    width: 100%;
                    font-size: 10px;
                    color: var(--gh-text3);
                }
            }
            .operate{
                width: 70px;
                text-align: center;
                align-items: center;
                .van-button{
                    height: 25px;
                    font-size: 12px;
                   background-color: var(--gh-primary);
                   &:nth-child(2){
                    margin-top: 10px;
                    background-color: pink;
                   }
                }
            }
          }
            
         }


     }
}

</style>
